package com.gitee.wsl.doc.opml

import com.gitee.wsl.doc.SampleReader
import com.gitee.wsl.doc.opml.bean.Outline
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull
import kotlin.test.assertTrue


class PlacesLivedTest {
    @Test
    @Throws(OpmlParseException::class)
    fun test() {
        val opml = SampleReader.parse("/opml/placesLived.opml")

        assertEquals("2.0", opml.version)
        assertEquals("placesLived.opml", opml.head.title)
        assertEquals("Mon, 27 Feb 2006 12:09:48 GMT", opml.head.dateCreated)
        assertEquals("Mon, 27 Feb 2006 12:11:44 GMT", opml.head.dateModified)
        assertEquals("Dave Winer", opml.head.ownerName)
        assertEquals("http://www.opml.org/profiles/sendMail?usernum=1", opml.head.ownerId)
        assertEquals(mutableListOf(1, 2, 5, 10, 13, 15), opml.head.expansionState)
        assertNull(opml.head.vertScrollState)
        assertTrue(242 == opml.head.windowTop)
        assertTrue(329 == opml.head.windowLeft)
        assertTrue(665 == opml.head.windowBottom)
        assertTrue(547 == opml.head.windowRight)

        assertEquals(1, opml.body.outlines.size)

        val outline = opml.body.outlines[0]
        assertEquals("Places I've lived", outline.getAttribute("text"))
        assertEquals(6, outline.subElements.size)

        var suboutline: Outline? = null
        var subsuboutline: Outline? = null

        suboutline = outline.subElements[0]
        assertEquals("Boston", suboutline.getAttribute("text"))
        assertEquals(2, suboutline.subElements.size)

        subsuboutline = suboutline.subElements[0]
        assertEquals("Cambridge", subsuboutline.getAttribute("text"))
        assertEquals(0, subsuboutline.subElements.size)

        subsuboutline = suboutline.subElements[1]
        assertEquals("West Newton", subsuboutline.getAttribute("text"))
        assertEquals(0, subsuboutline.subElements.size)

        suboutline = outline.subElements[1]
        assertEquals("Bay Area", suboutline.getAttribute("text"))
        assertEquals(4, suboutline.subElements.size)

        subsuboutline = suboutline.subElements[0]
        assertEquals("Mountain View", subsuboutline.getAttribute("text"))
        assertEquals(0, subsuboutline.subElements.size)

        subsuboutline = suboutline.subElements[1]
        assertEquals("Los Gatos", subsuboutline.getAttribute("text"))
        assertEquals(0, subsuboutline.subElements.size)

        subsuboutline = suboutline.subElements[2]
        assertEquals("Palo Alto", subsuboutline.getAttribute("text"))
        assertEquals(0, subsuboutline.subElements.size)

        subsuboutline = suboutline.subElements[3]
        assertEquals("Woodside", subsuboutline.getAttribute("text"))
        assertEquals(0, subsuboutline.subElements.size)

        suboutline = outline.subElements[2]
        assertEquals("New Orleans", suboutline.getAttribute("text"))
        assertEquals(2, suboutline.subElements.size)

        subsuboutline = suboutline.subElements[0]
        assertEquals("Uptown", subsuboutline.getAttribute("text"))
        assertEquals(0, subsuboutline.subElements.size)

        subsuboutline = suboutline.subElements[1]
        assertEquals("Metairie", subsuboutline.getAttribute("text"))
        assertEquals(0, subsuboutline.subElements.size)

        suboutline = outline.subElements[3]
        assertEquals("Wisconsin", suboutline.getAttribute("text"))
        assertEquals(1, suboutline.subElements.size)

        subsuboutline = suboutline.subElements[0]
        assertEquals("Madison", subsuboutline.getAttribute("text"))
        assertEquals(0, subsuboutline.subElements.size)

        suboutline = outline.subElements[4]
        assertEquals("Florida", suboutline.getAttribute("text"))
        assertEquals("include", suboutline.getAttribute("type"))
        assertEquals(
            "http://hosting.opml.org/dave/florida.opml",
            suboutline.getAttribute("url")
        )
        assertEquals(0, suboutline.subElements.size)

        suboutline = outline.subElements[5]
        assertEquals("New York", suboutline.getAttribute("text"))
        assertEquals(3, suboutline.subElements.size)

        subsuboutline = suboutline.subElements[0]
        assertEquals("Jackson Heights", subsuboutline.getAttribute("text"))
        assertEquals(0, subsuboutline.subElements.size)

        subsuboutline = suboutline.subElements[1]
        assertEquals("Flushing", subsuboutline.getAttribute("text"))
        assertEquals(0, subsuboutline.subElements.size)

        subsuboutline = suboutline.subElements[2]
        assertEquals("The Bronx", subsuboutline.getAttribute("text"))
        assertEquals(0, subsuboutline.subElements.size)
    }
}